/*
 * 
 * 
 */
package CONTROLLER;

import MODEL.Event;
import MODEL.Contact;
import MODEL.Dietplan;
import MODEL.EventHandler;
import MODEL.Journal;
import MODEL.Journalhandler;
import MODEL.Link;
import MODEL.Password;
import MODEL.Research;
import MODEL.ResearchHandler;
import MODEL.Shopping;
import VIEW.Contact_panel;
import VIEW.Dayplan_panel;
import VIEW.Dietplan_panel;
import VIEW.Event_panel;
import VIEW.Journal_panel;
import VIEW.Link_panel;
import VIEW.MainPanel;
import VIEW.Password_panel;
import VIEW.Research_panel;
import VIEW.RunFrame;
import VIEW.Shopping_panel;
import java.util.ArrayList;
import java.util.List;
import java.util.Observer;
import javax.swing.DefaultListModel;

/**
 *
 * @author Morten & Irene
 */
public class Controller {

    /// Attributes.
    private RunFrame runFrame;
    private MainPanel mainPanel;
    private Link_panel linkPanel;
    private Password_panel passPanel;
    private Contact_panel contactPanel;
    private Shopping_panel shoppingPanel;
    private Journal_panel journalPanel;
    private Event_panel eventPanel;
    private Dietplan_panel dietplanPanel;
    private Research_panel researchPanel;
    private Dayplan_panel dayplanPanel;
    private Contact contact;
    private Shopping shopping;
    private Journalhandler journals;
    private Dietplan dietplan;
    private Password passWord;
    private Link link;
    private Persister persister;
    private EventHandler eventHandler;
    private ResearchHandler researchHandler;


    // Constructor.
    public Controller() {
        runFrame = new RunFrame();
        contact = new Contact();
        shopping = new Shopping();
        journals = new Journalhandler();
        dietplan = new Dietplan();
        passWord = new Password();
        persister = new Persister();
        link = new Link();
        eventHandler = new EventHandler();
        researchHandler = new ResearchHandler();

        linkPanel = new Link_panel(this);
        passPanel = new Password_panel(this);
        contactPanel = new Contact_panel(this);
        journalPanel = new Journal_panel(this);
        shoppingPanel = new Shopping_panel(this);
        dietplanPanel = new Dietplan_panel(this);
        eventPanel = new Event_panel(this);
        researchPanel = new Research_panel(this);
        dayplanPanel = new Dayplan_panel(this);



        mainPanel = new MainPanel(this, linkPanel, passPanel, contactPanel, journalPanel, shoppingPanel, dietplanPanel, eventPanel, researchPanel, dayplanPanel);
        //Show mainPanel and set visibility to true:
        showMainPanel();
        runFrame.setVisible(true);
    }

    /*adds a observer to this class, and makes the contact class run the addobserver method.
     * @param o the observer object
     * */
    public void addObserver(Observer o) {
        contact.addObserver(o);
        shopping.addObserver(o);
        dietplan.addObserver(o);
        passWord.addObserver(o);
        journals.addObserver(o);
        eventHandler.addObserver(o);
        link.addObserver(o);
        researchHandler.addObserver(o);
    }

    public void showMainPanel() {
        runFrame.setContentPane(mainPanel);
        runFrame.pack();
    }

    /* notifies the contact-class, and makes it add the string-objects
     * @param name the name
     * @param phoneNumber the phonenumber
     * @param addresse the persons addresse
     * @param email the email
     * @param note obtional comment
     * */
    public void addFamily(String name, String phoneNumber, String address, String email, String note) {
        //tells the contact class to add these objects.
        contact.addContactFamily(name, phoneNumber, address, email, note);
    }

    public void addFriend(String name, String phoneNumber, String address, String email, String note) {
        //tells the contact class to add these objects.
        contact.addContactFriend(name, phoneNumber, address, email, note);
    }

    public void addWork(String name, String phoneNumber, String address, String email, String note) {
        //tells the contact class to add these objects.
        contact.addContactWork(name, phoneNumber, address, email, note);
    }

    public void addGym(String name, String phoneNumber, String address, String email, String note) {
        //tells the contact class to add these objects.
        contact.addContactGym(name, phoneNumber, address, email, note);
    }

    public void addOther(String name, String phoneNumber, String address, String email, String note) {
        //tells the contact class to add these objects.
        contact.addContactOther(name, phoneNumber, address, email, note);
    }

    public void removeFamily(String s) {
        contact.removeFamily(s);
    }

    public void removeFriend(String s) {
        contact.removeFriend(s);
    }

    public void removeWork(String s) {
        contact.removeWork(s);
    }

    public void removeGym(String s) {
        contact.removeGym(s);
    }

    public void removeOther(String s) {

        contact.removeOther(s);
    }


    /*adds familylist to a list,
    @return the list
     */
    public DefaultListModel getFamilyList() {
        DefaultListModel list = new DefaultListModel();
        for (String s : contact.getFamily()) {
            list.addElement(s);
        }
        return list;

    }

    /*adds friendlist to a list
    @return the frlist
     */
    public DefaultListModel getFriendList() {
        DefaultListModel frList = new DefaultListModel();
        for (String s : contact.getFriends()) {
            frList.addElement(s);
        }
        return frList;

    }
    /*adds worklist to a list
    @return the wlist
     */

    public DefaultListModel getWorkList() {
        DefaultListModel wList = new DefaultListModel();
        for (String s : contact.getWork()) {
            wList.addElement(s);
        }
        return wList;

    }

    /*adds gymlist to a list
    @return the glist
     */
    public DefaultListModel getGymList() {
        DefaultListModel gList = new DefaultListModel();
        for (String s : contact.getGym()) {
            gList.addElement(s);
        }
        return gList;

    }


    /*adds otherlist to a list
    @return the olist
     */
    public DefaultListModel getOtherList() {
        DefaultListModel oList = new DefaultListModel();
        for (String s : contact.getOther()) {
            oList.addElement(s);
        }
        return oList;

    }
    //////////////////////////////Event////////////////////////////////////////////////////////

    /*Creates a new event
     * @param title creates a title
     * @param date creates a date
     */
    public void createEvent(String title, String date) {
        Event e = new Event(title, date);
        this.eventHandler.setActiveEvent(e);
        eventHandler.addEventToList(e);
    }

    /*Makes the event active.
     * @param o is the observerobject which updates the event to active
     * @param selectedevent makes the event active
     */
    public void selectEvent(Observer o, Object selectedEvent) {
        this.eventHandler.setActiveEvent((Event) selectedEvent);
        o.update((Event) selectedEvent, null);
    }

    public void removeEvent(Object event) {
        this.eventHandler.removeEventFromList((Event) event);
    }

    public void setYear(String year) {
        this.eventHandler.getActiveEvent().setYear(year);

    }

    public void setTime(String time) {
        this.eventHandler.getActiveEvent().setTime(time);

    }

    public void setNote(String note) {
        this.eventHandler.getActiveEvent().setNote(note);

    }

    /*adds an event if one is created
     * @return elist adds the list to defaultlist
     */
    public DefaultListModel getEventList() {
        DefaultListModel eList = new DefaultListModel();
        for (Event event : eventHandler.getEvents()) {
            eList.addElement(event);


        }

        return eList;
    }
    /*get the active eventyear but only if one is created. otherwise it returns "".
     */

    public String getActiveEventYear() {
        Event e = this.eventHandler.getActiveEvent();

        if (e != null) {
            return e.getYear();
        } else {
            return "";
        }
    }

    /*get the active eventtime but only if one is created. otherwise it returns "".
     */
    public String getActiveEventTime() {
        Event e = this.eventHandler.getActiveEvent();

        if (e != null) {
            return e.getTime();
        } else {
            return "";
        }

    }

    /*get the active eventnote but only if one is created. otherwise it returns "".
     */
    public String getActiveEventNote() {
        Event e = this.eventHandler.getActiveEvent();

        if (e != null) {
            return e.getNote();
        } else {
            return "";
        }

    }

    /*get the active eventtitle but only if one is created. otherwise it returns "".
     */
    public String getActiveTitle() {
        Event e = this.eventHandler.getActiveEvent();

        if (e != null) {
            return e.getTitle();
        } else {
            return "";
        }

    }
    /*get the active eventdate but only if one is created. otherwise it returns "".
     */

    public String getActiveDate() {
        Event e = this.eventHandler.getActiveEvent();

        if (e != null) {
            return e.getDate();
        } else {
            return "";
        }

    }
    /*collects all the previous methods and sets the date, time, year and note.
     * @param date is the date
     * @param time is the time
     * @param year is the year
     * @param note is a note
     */

    public void getEventDetails(String date, String time, String year, String note) {
        this.eventHandler.getActiveEvent().setDate(date);
        this.eventHandler.getActiveEvent().setTime(time);
        this.eventHandler.getActiveEvent().setYear(year);
        this.eventHandler.getActiveEvent().setNote(note);
    }


//////////////////////JOURNAL/////////////////////////////////////////////////////
    /*Calculates weight and adds to the active list
     * @param currweight is the current weight
     * @param goal is the result of the weight
     */
    public void calculateWeightResult(float currWeight, float goal) {
        this.journals.getActiveJournal().setCurrWeight(currWeight);
        this.journals.getActiveJournal().setGoal(goal);

        if (goal > currWeight) {
            this.journals.getActiveJournal().setResult(goal - currWeight);
        } else {
            this.journals.getActiveJournal().setResult(currWeight - goal);
        }

    }

    public void addToPositiveList(String note) {
        this.journals.getActiveJournal().addNoteToPositive(note);
    }

    public void addToNegativeList(String note) {
        this.journals.getActiveJournal().addNoteToNegative(note);
    }
    /* Adds the active journalobject to the collcted list of journals
     *@param title is the title of the journal
     */

    public void CreateJournal(String title) {
        Journal j = new Journal(title);
        this.journals.setActiveJournal(j);
        journals.addJournalToList(j);
    }

    /* updates the active journal.
     */
    public void selectJournal(Observer o, Object selectedJournal) {
        this.journals.setActiveJournal((Journal) selectedJournal);
        o.update((Journal) selectedJournal, null);
    }

    /*Removes the journal from the list
     */
    public void removeJournal(Object journal) {
        this.journals.removeJournalFromList((Journal) journal);
    }

    /* removes the positive list. If the list is empty when removed it adds a new arrayList.
     * @s is the added title of the list
     */
    public void removePositive(String s) {
        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            j.removePos(s);
        } else {
            new ArrayList<String>();
        }

    }
    /* removes the negative list. If the list is empty when removed it adds a new arrayList.
     * @s is the added title of the list
     */

    public void removeNegative(String s) {

        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            j.removeNeg(s);
        } else {
            new ArrayList<String>();
        }

    }
    /* adds the positive list. If the list is empty when added it adds a new arrayList.
     * @return arraylist if the list is empty.
     */

    public ArrayList<String> getPositive() {

        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            return j.getPositive();
        } else {
            return new ArrayList<String>();
        }

    }

    /* If the list is null it gets the positive list from the active journal and adds it as an element to the list
     * @return plist which is the new list
     */
    public DefaultListModel getPostiveList() {
        DefaultListModel pList = new DefaultListModel();

        if (this.journals.getActiveJournal() != null) {
            Journal j = this.journals.getActiveJournal();

            if (j != null) {
                for (String pos : j.getPositive()) {
                    pList.addElement(pos);
                }

            }
        }
        return pList;
    }

    /* If the list is null it gets the negative list from the active journal and adds it as an element to the list
     * @return nlist which is the new list
     */
    public DefaultListModel getnegativeList() {
        DefaultListModel nList = new DefaultListModel();
        if (this.journals.getActiveJournal() != null) {
            Journal j = this.journals.getActiveJournal();

            if (j != null) {
                for (String neg : j.getNegative()) {
                    nList.addElement(neg);
                }

            }
        }
        return nList;
    }
    /*Adds the object to the journallist
     * @return tlist is the updated list og journals
     */

    public DefaultListModel getJournalList() {
        DefaultListModel tList = new DefaultListModel();
        for (Journal journal : journals.getJournals()) {
            tList.addElement(journal);
        }

        return tList;
    }

    /* gets the active journal weight result but only if list is created, otherwise it returns 0.
     *
     */
    public float getActiveJournalResult() {
        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            return j.getResult();
        } else {
            return 0;
        }

    }
    /* gets the active journal current weight result but only if list is created, otherwise it returns 0.
     *
     */

    public float getActiveJournalCurrentWeight() {
        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            return j.getCurrWeight();
        } else {
            return 0;
        }

    }
    /* gets the active journal goal weight result but only if list is created, otherwise it returns 0.
     *
     */

    public float getActiveJournalGoal() {
        Journal j = this.journals.getActiveJournal();

        if (j != null) {
            return j.getGoal();
        } else {
            return 0;
        }

    }

/////////////////////////////////shopping//////////////////////////////////////////////////////

    /*Takes a list of groceries and adds it to mondaylist
     * @groceries is the name of the list it adds
     */
    public void getMonday(List<String> groceries) {
        shopping.addMondayGrocery(groceries);

    }

    public void getTuesday(List<String> groceries) {
        shopping.addTuesdayGrocery(groceries);

    }

    public void getWednesday(List<String> groceries) {
        shopping.addWednesdayGrocery(groceries);

    }

    public void getThursday(List<String> groceries) {
        shopping.addThursdayGrocery(groceries);

    }

    public void getFriday(List<String> groceries) {
        shopping.addFridayGrocery(groceries);

    }

    public void getSaturday(List<String> groceries) {
        shopping.addSaturdayGrocery(groceries);

    }

    public void getSunday(List<String> groceries) {
        shopping.addSundayGrocery(groceries);

    }

    /*Takes a list of groceries and adds it to standardlist
     * @groceries is the name of the list it adds
     */
    public void getStandard(List<String> groceries) {
        shopping.addToStandard(groceries);
    }

    public void removeStandardGrocery(String grocery) {
        shopping.removeFromStandard(grocery);
    }

    public void removeMonday(String s) {
        shopping.removeMonday(s);
    }

    public void removeTuesday(String s) {
        shopping.removeTuesday(s);
    }

    public void removeWednesday(String s) {
        shopping.removeWednesday(s);
    }

    public void removeThursday(String s) {
        shopping.removeThursday(s);
    }

    public void removeFriday(String s) {
        shopping.removeFriday(s);
    }

    public void removeSaturday(String s) {
        shopping.removeSaturday(s);
    }

    public void removeSunday(String s) {
        shopping.removeSunday(s);
    }

    /*Adds mondayList to the list.
     * @return mlist is the returned updated list.
     */
    public DefaultListModel getMondayList() {
        DefaultListModel mList = new DefaultListModel();
        for (String s : shopping.getMonday()) {
            mList.addElement(s);
        }

        return mList;
    }

    public DefaultListModel getTuesdayList() {
        DefaultListModel tList = new DefaultListModel();
        for (String s : shopping.getTuesday()) {
            tList.addElement(s);
        }

        return tList;
    }

    public DefaultListModel getWednesdayList() {
        DefaultListModel wList = new DefaultListModel();
        for (String s : shopping.getWednesday()) {
            wList.addElement(s);
        }

        return wList;
    }

    public DefaultListModel getThursdayList() {
        DefaultListModel thList = new DefaultListModel();
        for (String s : shopping.getThursday()) {
            thList.addElement(s);
        }

        return thList;
    }

    public DefaultListModel getFridayList() {
        DefaultListModel fList = new DefaultListModel();
        for (String s : shopping.getFriday()) {
            fList.addElement(s);
        }

        return fList;
    }

    public DefaultListModel getSaturdayList() {
        DefaultListModel sList = new DefaultListModel();
        for (String s : shopping.getSaturday()) {
            sList.addElement(s);
        }

        return sList;
    }

    public DefaultListModel getSundayList() {
        DefaultListModel suList = new DefaultListModel();
        for (String s : shopping.getSunday()) {
            suList.addElement(s);
        }

        return suList;
    }

    public DefaultListModel getStandardList() {
        DefaultListModel stList = new DefaultListModel();
        for (String s : shopping.getStandard()) {
            stList.addElement(s);
        }

        return stList;
    }

/////////////////////////////////////dietplan//////////////////////////////////////////////////////////////
    /*Adds a list of meals to monday
     * @meals is the meal that is being added
     */
    public void addMondayFood(List<String> meals) {
        dietplan.addMondayFood(meals);

    }

    public void addTuesdayFood(List<String> meals) {
        dietplan.addTuesdayFood(meals);

    }

    public void addWednesdayFood(List<String> meals) {
        dietplan.addWednesdayFood(meals);

    }

    public void addThursdayFood(List<String> meals) {
        dietplan.addThursdayFood(meals);

    }

    public void addFridayFood(List<String> meals) {
        dietplan.addFridayFood(meals);

    }

    public void addSaturdayFood(List<String> meals) {
        dietplan.addSaturdayFood(meals);

    }

    public void addSundayFood(List<String> meals) {
        dietplan.addSundayFood(meals);

    }

    public void addToStandard(List<String> meals) {
        dietplan.addToStandard(meals);
    }

    public void removeStandardMeal(String meal) {
        dietplan.removeFromStandard(meal);
    }

    public void removeMondayMeal(String s) {
        dietplan.removeMondayMeal(s);
    }

    public void removeTuesdayMeal(String s) {
        dietplan.removeTuesdaydayMeal(s);
    }

    public void removeWednesdayMeal(String s) {
        dietplan.removeWednesdayMeal(s);
    }

    public void removeThursdayMeal(String s) {
        dietplan.removeThursdayMeal(s);
    }

    public void removeFridayMeal(String s) {
        dietplan.removeFridayyMeal(s);
    }

    public void removeSaturdayMeal(String s) {
        dietplan.removeSaturdayMeal(s);
    }

    public void removeSundayMeal(String s) {
        dietplan.removeSundayMeal(s);
    }
    /*Gets a list of mondayFood and adds it to dietplanList monday.
     * @return list is the returned list
     */

    public DefaultListModel getMondayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getMonday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getTuesdayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getTuesday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getWednesdayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getWednesday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getThursdayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getThursday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getFridayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getFriday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getSaturdayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getSaturday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getSundayFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getSunday()) {
            List.addElement(s);
        }

        return List;
    }

    public DefaultListModel getStandardFoodList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : dietplan.getStandard()) {
            List.addElement(s);
        }

        return List;
    }
/////////////////////////////PASSWORD///////////////////////////////////////////////////////

    /*Adds a password to fitnessPassword using a title, username and password
     * @param title is the title of the password
     * @param username is the username for the password
     * @password is the password
     */
    public void addFitnessPassword(String title, String username, String password) {
        passWord.addFitnessPassword(title, username, password);

    }

    public void addVipPassword(String title, String username, String password) {
        passWord.addWorkPassword(title, username, password);
    }

    public void addOtherPassword(String title, String username, String password) {
        passWord.addMiscPassword(title, username, password);
    }

    /*removes the password from the list
     * @param title is the title of the removed password
     */
    public void removeFittnessP(String title) {
        passWord.removeFitnessPassword(title);
    }

    public void removeVIPP(String title) {
        passWord.removeWorkPassword(title);
    }

    public void removeOtherP(String title) {
        passWord.removeMiscPassword(title);
    }

    /*Get the fitnessList and adds the objects to the defaultlist
     * @return list is the new updated list
     */
    public DefaultListModel getFitnessList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : passWord.getFitness()) {
            List.addElement(s);
        }

        return List;
    }

    /*Get the VIPList and adds the objects to the defaultlist
     * @return list is the new updated list
     */
    public DefaultListModel getVipList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : passWord.getWork()) {
            List.addElement(s);
        }

        return List;
    }

    /*Get the MiscList and adds the objects to the defaultlist
     * @return list is the new updated list
     */
    public DefaultListModel getMiscList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : passWord.getMisc()) {
            List.addElement(s);
        }

        return List;
    }
////////////////////////////////LINK/////////////////////////////////////////////////////

    /*Adds a funLink to the list via a title and URL
     * @param title is the title of the link
     * @param url is the webaddress
     */
    public void addFunLink(String title, String url) {
        link.addFunLink(title, url);
    }

    public void addWorkLink(String title, String url) {
        link.addWorkLink(title, url);
    }

    public void addOtherLink(String title, String url) {
        link.addMiscLink(title, url);
    }

    public void addFitnessLink(String title, String url) {
        link.addExerciseLink(title, url);
    }

    public void removeFunLink(String s) {
        link.removeFunLink(s);
    }

    public void removeWorkLink(String s) {
        link.removeWorkLink(s);
    }

    public void removeOtherLink(String s) {
        link.removeMiscLink(s);
    }

    public void removeFitnessLink(String s) {
        link.removeExerciseLink(s);
    }
    
    /*Adds exerciseLinkList to the defaultlist
     * @return list is the updated list
     */

    public DefaultListModel getExerciseLinkList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : link.getExercise()) {
            List.addElement(s);
        }

        return List;
    }

    /*Adds funlinkList to the defaultlist
     * @return list is the updated list
     */
    public DefaultListModel getFunLinkList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : link.getFun()) {
            List.addElement(s);
        }

        return List;
    }

    /*Adds workLinkList to the defaultlist
     * @return list is the updated list
     */
    public DefaultListModel getWorkLinkList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : link.getWork()) {
            List.addElement(s);
        }

        return List;
    }

    /*Adds otherLinkList to the defaultlist
     * @return list is the updated list
     */
    public DefaultListModel getOtherLinkList() {
        DefaultListModel List = new DefaultListModel();
        for (String s : link.getMisc()) {
            List.addElement(s);
        }

        return List;
    }
/////////////////////////////////RESEARCH//////////////////////////////////////////

    /*Creates a researchnote via the updated and active list.
     * @param title is the title of the list
     * @param note is the note of the research.
     */
    public void createResearchNote(String title, String note) {
        Research r = new Research(title, note);
        this.researchHandler.setActiveResearch(r);
        this.researchHandler.addResearchNoteToList(r);
    
    }

    /*Updates the researchNote to the active list.
     *
     */
    public void selectResearchNote(Observer o, Object selectedResearchNote) {
        this.researchHandler.setActiveResearch((Research) selectedResearchNote);
        o.update((Research) selectedResearchNote, null);
    }

    public void removeResearchNote(Object research) {
        this.researchHandler.removeResearchNoteFromList((Research) research);
    }

    public void setResearchNote(String note) {
        this.researchHandler.getActiveResearchNote().setNote(note);

    }

    /*Adds the ResearchList to the defaultlist and returns the list
     * @param elist is the updated list
     */
    public DefaultListModel getResearchList() {
        DefaultListModel eList = new DefaultListModel();
        for (Research research : researchHandler.getResearchNotes()) {
            eList.addElement(research);


        }

        return eList;
    }

    /* If there is no active list it returns ""
     */
    public String getActiveResearchNote() {
        Research r = this.researchHandler.getActiveResearchNote();

        if (r != null) {
            return r.getNote();
        } else {
            return "";
        }

    }

    /* If there is no active researchTitle it return a ""
     */
    public String getActiveResearchTitle() {
        Research r = this.researchHandler.getActiveResearchNote();

        if (r != null) {
            return r.getTitle();
        } else {
            return "";
        }

    }

    public void getResearchNoteDetails(String title, String note) {
        this.researchHandler.getActiveResearchNote().setNote(note);
        this.researchHandler.getActiveResearchNote().setTitle(title);



    }

//////////////////////////////////Persister///////////////////////////////////////
    // A class which is in charge of all the save and load properties.
    
    /* Saves journalobjects via the persister. 
     */
    public void saveJournals() {
        persister.save(journals, "journals.dat");
    }
    /* Loads the journalobjects via the persister.
    */
    public void loadJournals() {
        journals = (Journalhandler) persister.load("journals.dat");
    }

    public void saveContacts() {
        persister.save(contact, "contact.dat");
    }

    public void loadContacts() {
        contact = (Contact) persister.load("contact.dat");
    }

    public void saveDietplan() {
        persister.save(dietplan, "dietplan.dat");
    }

    public void loadDietplan() {
        dietplan = (Dietplan) persister.load("dietplan.dat");
    }

    public void saveEvent() {
        persister.save(eventHandler, "event.dat");
    }

    public void loadEvent() {
        eventHandler = (EventHandler) persister.load("event.dat");
    }

    public void saveLink() {
        persister.save(link, "link.dat");
    }

    public void loadLink() {
        link = (Link) persister.load("link.dat");
    }

    public void savePassword() {
        persister.save(passWord, "password.dat");
    }

    public void loadPassword() {
        passWord = (Password) persister.load("password.dat");
    }

    public void saveResearch() {
        persister.save(researchHandler, "research.dat");
    }

    public void loadResearch() {
        researchHandler = (ResearchHandler) persister.load("research.dat");
    }

    public void saveShopping() {
        persister.save(shopping, "shopping.dat");
    }

    public void loadShopping() {
        shopping = (Shopping) persister.load("shopping.dat");
    }

}
